<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/css/layui.css}">
    <script th:src="@{/layui.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script id="toolbarDemo" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>
<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function(){
        var table = layui.table;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow
        table.render({
            elem: '#test'
            ,url:'/courseorder/listJson'
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,totalRow: true
            ,cols: [
                [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'uuid', title:'ID', width:300,fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                ,{field:'wechat_no', title:'微信号', width:80, edit: 'text'}
                ,{field:'name', title:'姓名', width:80, edit: 'text'}
                ,{field:'course_name', title:'课程名称', width:180, edit: 'text'}
                ,{field:'course_price', title:'课程价格', width:100, edit: 'text'}
                ,{field:'order_date', title:'下单日期', width:120}
                ,{field:'update_datetime', title:'下单时间', width:120}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]
            ]
            ,page: true
        });

        //监听行双击事件
        table.on('rowDouble(test)', function (obj) {
            //obj 同上
            var order_id = obj.data.order_id;
            parent.layer.open({
                type: 2,//2跳转到页面
                offset: 'auto',
                title: '课程订单详情',
                content: '/courseorder/detail?order_id=' + order_id,
                area: ['1000px', '600px'],
                btn: '关闭全部',
                btnAlign: 'c',
                yes: function () {
                    parent.layer.closeAll();
                }
            });
        });

        //工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    //layer.msg("弹出一个添加界面");
                    parent.layer.open({
                        type:2,//2跳转到页面
                        offset: 'auto',
                        title:'添加课程订单',
                        content:'/courseorder/add',
                        area: ['1000px', '600px'],
                        btn:'关闭全部',
                        btnAlign:'c',
                        yes:function () {
                            parent.layer.closeAll();
                        }
                    });
                    break;
            };
        });
    });
</script>

</body>
</html>